package com.pms.eap.relationship;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class PartyRelationship implements Serializable{
	
	private static final long serialVersionUID = -1516282656729772142L;
	private Integer id;
	
	private PartyRelationshipType partyRelationshipType;
	
	private Party partyParent;
	private Party partyChild;
	private Date validFrom;
	private Date validTo;
//	private List<FieldPermission> fieldPermissions;

	public void setId(Integer id) {
		this.id = id;
	}

	@Id
	@GeneratedValue
	public Integer getId() {
		return id;
	}

	public void setPartyRelationshipType(PartyRelationshipType partyRelationshipType) {
		this.partyRelationshipType = partyRelationshipType;
	}

	@ManyToOne(targetEntity = PartyRelationshipType.class,fetch=FetchType.EAGER)
	public PartyRelationshipType getPartyRelationshipType() {
		return partyRelationshipType;
	}
	
	
	public void setPartyParent(Party partyParent) {
		this.partyParent = partyParent;
	}

	@ManyToOne(targetEntity = Party.class,fetch=FetchType.EAGER)
//	@JoinColumn(name="partyParent")
	public Party getPartyParent() {
		return partyParent;
	}

	public void setPartyChild(Party partyChild) {
		this.partyChild = partyChild;
	}

	@ManyToOne(targetEntity = Party.class,cascade=CascadeType.MERGE,fetch=FetchType.EAGER)
	public Party getPartyChild() {
		return partyChild;
	}
	
	public Date getValidFrom() {
		return validFrom;
	}

	public void setValidFrom(Date validFrom) {
		this.validFrom = validFrom;
	}

	public Date getValidTo() {
		return validTo;
	}

	public void setValidTo(Date validTo) {
		this.validTo = validTo;
	}
	
	@Transient
	public boolean valid(){
		return true;
	}

//	public void setFieldPermissions(List<FieldPermission> fieldPermissions) {
//		this.fieldPermissions = fieldPermissions;
//	}
//
//	@OneToMany(targetEntity=FieldPermission.class,mappedBy="parent",cascade = CascadeType.ALL)
//	public List<FieldPermission> getFieldPermissions() {
//		if (fieldPermissions == null){
//			fieldPermissions = new ArrayList<FieldPermission>();
//		}
//		return fieldPermissions;
//	}

}
